﻿//window.onerror = function () {
//    //Don't do anything, just supress the error
//}

function base64_decode(data) {

  
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
    ac = 0,
    dec = "",
    tmp_arr = [];

    if (!data) {
        return data;
    }

    data += '';

    do { // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;

        o1 = bits >> 16 & 0xff;
        o2 = bits >> 8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);

    dec = tmp_arr.join('');

    return dec;
}

function base64_encode(data) {
 
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
    ac = 0,
    enc = "",
    tmp_arr = [];

    if (!data) {
        return data;
    }

    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1 << 16 | o2 << 8 | o3;

        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;
        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);

    enc = tmp_arr.join('');

    var r = data.length % 3;

    return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);

}


function resizeIframe(id){
    var newheight;
    var newwidth;

    if(document.getElementById){
      //  newheight=document.getElementById(id).contentWindow.document.body.scrollHeight+50;
        //  newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
        newheight = (document.body.parentNode.scrollHeight)-95 
    }

    document.getElementById(id).height = (newheight) + "px";
    document.getElementById(id).style.height = (newheight) + "px";

}

function resizeIframedir(efr) {
    var newheight;
    var newwidth;

    if (document.getElementById) {
        //  newheight=document.getElementById(id).contentWindow.document.body.scrollHeight+50;
        //  newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
        newheight = (document.body.parentNode.scrollHeight) - 95
    }

    efr.height = (newheight) + "px";
    //efr.style.height = (newheight) + "px";

}


function strEndsWith(str, suffix) {
    return str.match(suffix + "$") == suffix;
}


function GetElement(elemId) {

    var elemFullId = GetElementByIdEndsWith(elemId);
    var editor = aspxGetControlCollection().Get(elemFullId.id);
    return editor;
}

function FindControl(parentControl, strId) {
    var returnObject;
    for (i = 0; i < parentControl.elements.length; i++) {
        if (parentControl.elements[i].id.indexOf(strId) >= 0)
            returnObject = parentControl.elements[i];
        else if (parentControl.elements[i].hasChildNodes())
            returnObject = FindControl(parentControl.elements[i], strId);

        if (returnObject != null) {   //if object is found return
            return returnObject;
        }
    }
    return returnObject;
} 

function GetElementByIdEndsWith(endsWith) {


    var elements =    document.getElementsByTagName("*");

    for (var i = 0; i < elements.length; i++) {
        if (elements[i].id.endsWith(endsWith)) {
            return elements[i];
        }
    }

    return null;
}

function getElement(id) {
    if (document.getElementById) {
        return document.getElementById(id);
    }
    else if (document.all) {
        return window.document.all[id];
    }
    else if (document.layers) {
        return window.document.layers[id];
    }
}

function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null) {
        node = document;
    }

    if (tag == null) {
        tag = '*';
    }

    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");

    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}


String.prototype.endsWith = function (txt, ignoreCase) {
    var rgx;

    if (ignoreCase) {
        rgx = new RegExp(txt + "$", "i");
    }
    else {
        rgx = new RegExp(txt + "$");
    }

    return this.match(rgx) != null;
}

function validateID(idVal) {
    var checkDigit = parseInt(idVal.charAt(idVal.length - 1));
    var odd = 0;
    var even = "";
    var evenResult = 0;
    var result;
    for (var c = 1; c <= idVal.length; c++) {
        if (c % 2 == 0) {
            even += idVal.charAt(c - 1);
        } else {
            if (c == idVal.length) {
                continue;
            } else {
                odd = (parseInt(odd) + parseInt(idVal.charAt(c - 1)));
            }
        }
    }
    even = (Number(even) * 2);
    even = even.toString();
    for (var r = 1; r <= even.length; r++) {
        evenResult = (parseInt(evenResult) + parseInt(even.charAt(r - 1)));
    }
    result = (parseInt(odd) + parseInt(evenResult));
    result = result.toString();
    result = (10 - parseInt(result.charAt(result.length - 1)));
    result = result.toString();
    if (result.length > 1) {
        result = result.charAt(result.length - 1);
    }
    if (parseInt(result) != checkDigit) {
        return false;
    } else {
        return true;
    }
} 

function toggleVisibility(me) {
    if (me.style.visibility == "hidden") {
        me.style.visibility = "visible";
    }
    else {
        me.style.visibility = "hidden";
    }
}
function toggleDisabled(me) {
    if (me.disabled == "disabled") {
        me.disabled = "enabled";
    }
    else {
        me.disabled = "disabled";
    }
}
function getRequestParameter(name) {
    name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');
    var regexS = '[\\?&]' + name + '=([^&#]*)';
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return '';
    else
        return results[1];
}
function DoSearch(search) {
    var str1, str2;
    str1 = window.location.href;
    str2 = str1.replace("&criteria=" + getRequestParameter('criteria'), "");
    window.location.href = str2 + '&criteria=' + search;
}


/***********************************************
* Tab Content script- ? Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab = [1, "tab1"]

////////Stop editting////////////////

function cascadedstyle(el, cssproperty, csspropertyNS) {
    if (el.currentStyle)
        return el.currentStyle[cssproperty]
    else if (window.getComputedStyle) {
        var elstyle = window.getComputedStyle(el, "")
        return elstyle.getPropertyValue(csspropertyNS)
    }
}

var previoustab = ""

function expandcontent(cid, aobject) {
    if (document.getElementById) {
        highlighttab(aobject)
        detectSourceindex(aobject)
        if (previoustab != "")
            document.getElementById(previoustab).style.display = "none"
        document.getElementById(cid).style.display = "block"
        previoustab = cid
        if (aobject.blur)
            aobject.blur()
        return false
    }
    else
        return true
}

function highlighttab(aobject) {
    if (typeof tabobjlinks == "undefined")
        collecttablinks()
    for (i = 0; i < tabobjlinks.length; i++)
        tabobjlinks[i].style.backgroundColor = initTabcolor
    var themecolor = aobject.getAttribute("theme") ? aobject.getAttribute("theme") : initTabpostcolor
    aobject.style.backgroundColor = document.getElementById("tabcontentcontainer").style.backgroundColor = themecolor
}

function collecttablinks() {
    var tabobj = document.getElementById("tablist")
    tabobjlinks = tabobj.getElementsByTagName("A")
}

function detectSourceindex(aobject) {
    for (i = 0; i < tabobjlinks.length; i++) {
        if (aobject == tabobjlinks[i]) {
            tabsourceindex = i //source index of tab bar relative to other tabs
            break
        }
    }
}

function do_onload() {
    var cookiename = (typeof persisttype != "undefined" && persisttype == "sitewide") ? "tabcontent" : window.location.pathname
    var cookiecheck = window.get_cookie && get_cookie(cookiename).indexOf("|") != -1
    collecttablinks()
    initTabcolor = cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
    initTabpostcolor = cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
    if (typeof enablepersistence != "undefined" && enablepersistence && cookiecheck) {
        var cookieparse = get_cookie(cookiename).split("|")
        var whichtab = cookieparse[0]
        var tabcontentid = cookieparse[1]
        expandcontent(tabcontentid, tabobjlinks[whichtab])
    }
    else {
        if (initialtab[1] != "undefined") {
            expandcontent(initialtab[1], tabobjlinks[initialtab[0] - 1]);
        }
    }

}





